package com.smarthome.rpc.base;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Aspect
@Service("rpcLoggerAspect")
public class RpcLoggerAspect {
    private static final Logger LOGGER = LoggerFactory.getLogger(RpcLoggerAspect.class);
//    @Before("execution(* com.smarthome.orders.rpc.service.impl.*.*(..))") 
//    public void before(){
//        
//    }
//    @After("execution(* com.smarthome.orders.rpc.service.impl.*.*(..))") 
//    public void after(){
//        
//    }
    @Around("execution(* com.smarthome.rpc.*.*(..))")  
    public Object processTx(ProceedingJoinPoint jp) throws java.lang.Throwable {  
        long curr = System.currentTimeMillis();
        Object rvt = jp.proceed();  
        String className = jp.getTarget().getClass().getName() + "."+ jp.getSignature().getName();
        curr = System.currentTimeMillis()-curr;
        if(curr>1000){//接口调用超过1000秒输出日志
            LOGGER.warn(String.format("接口%s调用耗时:%d毫秒",className,curr)); 
        }
        return rvt;  
    }  
}

